package com.lanou.userLogin.book.service;

import com.lanou.userLogin.book.dao.BookDao;
import com.lanou.userLogin.book.dao.BookDaoImpl;
import com.lanou.userLogin.book.domain.Book;

import java.util.ArrayList;
import java.util.List;

public class BookService {

    private BookDao bd = new BookDaoImpl();

    public List<Book> findAll() {
        List<Book> allBook = bd.findAllBook();
        if (allBook.size() == 0) {
            System.out.println("啥也没有");
        } else {
            return allBook;
        }
        return new ArrayList<>();
    }

    public List<Book> findAllByCname(String cname) {
        List<Book> allBook = bd.findAllBookByCname(cname);
        if (allBook.size() == 0) {
            System.out.println("啥也没有");
        } else {
            return allBook;
        }
        return new ArrayList<>();
    }

    public List<Book> choose(String cname){
        if("allCategory".equals(cname)){
            return findAll();
        }else {
            return findAllByCname(cname);
        }
    }

    public List<Book> oneBookLoad(String bid){
        List<Book> books = bd.oneBookInfo(bid);
        return books;
    }

    public Book oneBook(String bid){
        Book books = bd.oneBook(bid);
        return books;
    }
}
